package com.test;

public class person {
    private String name;
    private int age;

    public person() {
    }

    public person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

//    public void keepPet(cat a,String s)
//    {
//        System.out.println(this.age+"岁的"+this.name+"养了一只猫");
//        a.eat(s);
//    }
    public void keepPet(animal a,String s)
    {
        if(a instanceof dog d)
        {
            //如果a多态右侧是dog右侧是dog就强转为dog类型
            System.out.println(this.age+"岁的"+this.name+"养了一只狗");
            d.eat(s);
        }
        else
        {
            System.out.println(this.age+"岁的"+this.name+"养了一只猫");
            a.eat(s);
        }

    }
}
